package com.cn.yunhe.rentcars.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.cn.yunhe.rentcars.mapper.ResourceMapper;
import com.cn.yunhe.rentcars.model.Resource;

@RestController
public class MenuController {
	@Autowired
	private ResourceMapper resourceMapper;
	@RequestMapping(value="/getResToMenu",method=RequestMethod.GET)
	public List<Map<String,String>> getResToJson(){
		System.out.println("从数据库查询权限资源信息,生成json格式");
		Map<String,String> mapJson = null;
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		Map<String,String> map = new HashMap<String,String>();//模糊查询时传递参数。
		List<Resource> resList = resourceMapper.findResources(map);
		
		for(Resource rc : resList){
			if(!rc.getPermistype().equals("3")){
				mapJson = new HashMap<String,String>();
				mapJson.put("id", rc.getPermisid());
				mapJson.put("pId", rc.getParentid());
				mapJson.put("name",rc.getPermisname());
				mapJson.put("resType", rc.getPermistype());
				list.add(mapJson);
			}			
		}
		return list;
	}
	@RequestMapping(value="/menu",method=RequestMethod.GET)
	public ModelAndView menuPage(){
		Map<String,String> map = new HashMap<String,String>();
		List<Resource> resList = resourceMapper.findResources(map);
		Map<String,Object> rsMap = new HashMap<String,Object>();
		System.out.println("总长度："+resList.size());
		rsMap.put("resList", resList);
		return new ModelAndView("sysmenu",rsMap);
	}
}
